const Koa = require('koa');
const path = require('path');
const logger = require('koa-logger');
const static = require('koa-static');
const router = require('koa-router')()
const views = require('koa-views');
var fm = require('./lib/freemarker.js');

fm.templateDir = path.join(__dirname, 'templates');

const app = new Koa();

//设置静态资源目录
var publicFiles = static(path.join(__dirname, 'public'));
publicFiles._name = 'static';

app.use(logger());

/**
 * 静态资源处理
 */
app.use(publicFiles);

/**
 * 配置页面模板
 */
app.use(views(path.join(__dirname, '/templates'), { extension: 'ejs' }));



router.get('/index', async function(ctx) {
	await fm.render(ctx, 'index.ftl', {tdk : {title : '大标题'}});
})

app.use(router.routes());


app.listen(3000);